package ${package}.${module.packageName}.web;

import java.util.List;

<@point name="JAVA:IMPORT" />
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

<#assign classComment = "${module.explain}控制器">
<#include "../javadoc/classComment.ftl">
@RestController
@RequestMapping("${extParam.REQUEST_PREFIX!}/${module.name ? uncap_first}")
@Api(tags="${module.explain}")
public class ${module.name}Controller {
	
	<@point name="JAVA:MEMBER" />
	
	@ApiOperation(value = "新增${module.explain}")
	@ApiImplicitParams({
	<#list module.fields as field>
	@ApiImplicitParam(name = "${field.name}", value = "${field.explain}", paramType = "query"),
	</#list>
	})
	@PostMapping
	public JsonObject<Object> add${module.name}(@ApiIgnore ${module.name} ${module.name ? uncap_first},@RequestHeader(name = "authService.USERID") String userID){
		<@point name="JAVA:METHOD_BODY:ADD" post="return new JsonSuccessObject<>(${module.name ? uncap_first});"/>
	}
	
	@ApiOperation(value = "更新${module.explain}")
	@ApiImplicitParams({
	<#list module.fields as field>
	@ApiImplicitParam(name = "${field.name}", value = "${field.explain}", paramType = "query"),
	</#list>
	})
	@PutMapping
	public JsonObject<Object>  update${module.name}(@ApiIgnore ${module.name} ${module.name ? uncap_first}){
		<@point name="JAVA:METHOD_BODY:UPDATE" post="return new JsonSuccessObject<>(${module.name ? uncap_first});"/>
	}
	
	@ApiOperation(value = "批量删除${module.explain}")
	@ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "${module.explain}ID", paramType = "query", allowMultiple = true) })
	@DeleteMapping
	public JsonObject<Object> delete${module.name}(String[] ids){
		<@point name="JAVA:METHOD_BODY:DELETE" post="return JsonSuccessObject.SUCCESS;"/>
	}
	
	@ApiOperation(value = "根据${module.explain}ID查询${module.explain}信息")
	@ApiImplicitParams({ @ApiImplicitParam(name = "${(module.name + "ID") ? uncap_first}", value = "${module.explain}ID", paramType = "path") })
	@GetMapping("/{${(module.name + "ID") ? uncap_first}}")
	public JsonObject<${module.name}> get${module.name}(@PathVariable("${(module.name + "ID") ? uncap_first}")String ${(module.name + "ID") ? uncap_first}){
		<@point name="JAVA:METHOD_BODY:GET" default="return new JsonSuccessObject(new ${module.name}());"/>
	}
	
	@GetMapping
	@ApiOperation(value = "分页查询${module.explain}信息")
	@ApiImplicitParams({
	<#list module.fields as field>
	<#if (field.constraint.queryType)??>
	@ApiImplicitParam(name = "search${field.name ? cap_first}", value = "查询${field.explain}", paramType = "query"),
	</#if>
	</#list>
	})
	public JsonQueryObject<${module.name}> list${module.name}(@ApiIgnore ${module.name}Query query){
		<@point name="JAVA:METHOD_BODY:LIST" default="return new JsonQueryObject<>(query);"/>
	}
	
	<@point name="JAVA:METHOD"/>
}